{% extends 'leave/admin.html' %}
{% block content %}

<script type="text/javascript">
	app.controller('content',function ($scope,$http) {
		var empid='{{empid}}';
		$scope.view='home';
		$scope.get_submited_leave=function () {
			$scope.view='leaves';
			if (!empid)return;
			var postData = {
					get_submited_leave:{staff:empid},
				};  
			$http.post('',postData)
			.success(function(data, status, headers, config) {  
				$scope.leaves=data.get_submited_leave.leaves;
		    
			}).error(function(data, status, headers, config) {  
			    //处理错误 
			    $scope.std='有错误,返回码为:'+status;
			});
		}

		$scope.get_leave_need_approve=function () {
			$scope.view='need_approve';
			if (!empid)return;
			var postData = {
					get_leave_need_approve:{staff:empid},
				};  
			$http.post('',postData)
			.success(function(data, status, headers, config) {  
				$scope.func_leader_msg=data.get_leave_need_approve.func_leader_msg;
				$scope.pro_leader_msg=data.get_leave_need_approve.pro_leader_msg;
		    
			}).error(function(data, status, headers, config) {  
			    //处理错误 
			    $scope.std='有错误,返回码为:'+status;
			});
		}

		$scope.submit_approve= function () {
			var func_items=[];
			var pro_items=[];
			for (x in $scope.func_leader_msg){
				leave=$scope.func_leader_msg[x];
				func_items.push({id:leave.id,func_leader_approved:leave.func_leader_approved,msg_id:leave.msg_id})
			}
			for (x in $scope.pro_leader_msg){
				leave=$scope.pro_leader_msg[x];
				pro_items.push({id:leave.id,pro_leader_approved:leave.pro_leader_approved,msg_id:leave.msg_id});
			}
			var postData = {
					approve_leave:{func_items:func_items,pro_items:pro_items},
				};  
			$http.post('',postData)
			.success(function(data, status, headers, config) {  
				alert('提交成功')
		    
			}).error(function(data, status, headers, config) {  
			    //处理错误 
			    $scope.std='有错误,返回码为:'+status;
			});
		}

		$scope.realtime_leave=function () {
			$scope.view='realtime_info';
			var postData = {
					realtime_leave:{staff:empid},
				};  
			$http.post('',postData)
			.success(function(data, status, headers, config) {  
				$scope.real_info=data.realtime_leave;
		    
			}).error(function(data, status, headers, config) {  
			    //处理错误 
			    $scope.std='有错误,返回码为:'+status;
			});
		}
		$scope.switch_to_attend=function () {
			$scope.view='attend_view';
		}
		$scope.import_attend=function () {
			var postData = {
					import_attend:{},
				};  
			$http.post('',postData)
			.success(function(data, status, headers, config) {  
				alert('ok');
		    
			}).error(function(data, status, headers, config) {  
			    //处理错误 
			    $scope.std='有错误,返回码为:'+status;
			});
			
		};
		$scope.report_attend=function () {
			var postData = {
					update_report:{},
				};  
			$http.post('',postData)
			.success(function(data, status, headers, config) {  
				alert('ok');
		    
			}).error(function(data, status, headers, config) {  
			    //处理错误 
			    $scope.std='有错误,返回码为:'+status;
			});
			
		};
		$scope.leave={};
		$scope.apply_leave=function (b) {
					if(!b)return
					var leave = $scope.leave;
					var postData = {
							submit_leave:{staff:empid,category:leave.category,start_time:leave.start_time,end_time:leave.end_time,
							reason:leave.reason},
						};  
					$http.post('',postData)
					.success(function(data, status, headers, config) {  
						var status=data.submit_leave.status;
						if (status=='success'){
							alert('提交成功');
						}else{
							alert(data.submit_leave.msg);
						}
						
				    
					}).error(function(data, status, headers, config) {  
					    //处理错误 
					    $scope.std='有错误,返回码为:'+status;
					});
				}
		$scope.complet_staff=function () {
					var postData = {
						jj:{}
						};  
					$http.post('',postData)
					.success(function(data, status, headers, config) {  
						alert('提交成功');
				    
					}).error(function(data, status, headers, config) {  
					    //处理错误 
					    $scope.std='有错误,返回码为:'+status;
					});
		}
		$scope.get_leave_msg=function () {
					$scope.view="home";
					var postData = {
						get_msg:{empid:empid}
						};  
					$http.post('',postData)
					.success(function(data, status, headers, config) {  
						$scope.msgs=data.get_msg.msgs;
				    
					}).error(function(data, status, headers, config) {  
					    //处理错误 
					    $scope.std='有错误,返回码为:'+status;
					});
		}
	});
</script>

<div ng-controller='content' class='container'>
	<div class="col-md-3">
		<ul>
			<li><a href="" ng-click='get_leave_msg()'>home</a></li>
			<li><a href="" ng-click='view="apply_leave"'>请假</a></li>
			<li><a href="" ng-click='get_submited_leave()'>已经提交的请假</a></li>
			<li><a href="" ng-click='get_leave_need_approve()'>等待你处理的请假</a></li>
			<li><a href="" ng-click='realtime_leave()'>实时假期查询</a></li>
			<li><a href="" ng-click='switch_to_attend()'>操作考勤</a></li>
			<li><a href="" ng-click='view="links"'>临时连接</a></li>
		</ul>
	</div>
	<div class="col-md-9" ng-switch="view">
		<!------------------------------------------->
		<div ng-switch-when='home'>
			以某员工身份登录

			<table class="table table-hover">
				<tr>
					<th>员工</th>
					<th>消息时间</th>
					<th>消息内容</th>
				</tr>
				<tr ng-repeat='msg in msgs'>
					<td ng-bind='msg.name'></td>
					<td ng-bind='msg.time'></td>
					<td ng-bind='msg.content'></td>
				</tr>
			</table>
		</div>
		<!--------------请假------------------------>
		<div ng-switch-when='apply_leave'>
			<form name="myForm" ng-submit="apply_leave(myForm.$valid)" novalidate>
				<label for="">请假类型</label>
				  	<select class="form-control" ng-model='leave.category'>
					  <option value ="annual">年假</option>
					  <option value ="sick">病假</option>
					  <option value="personal">事假</option>
					  <option value="birthday">生日假</option>
					  <option value="swap_off">调休</option>
					  <option value="other">其他</option>
					</select>
				<label for="">请假起止时间</label>
				<input type="datetime-local" name='start_time' ng-model='leave.start_time'>
				<input type="datetime-local" name='end_time' ng-model='leave.end_time'>
				<label for="reason">理由</label>
				<input type="text" name='reason' ng-model='leave.reason'>
				<input type="submit" value='提交'>
			</form>
		</div>
		
		<!------------------------------------------->
		<div ng-switch-when='leaves'>
			<table class="table table-hover">
				<tr>
					<th>员工</th>
					<th>类型</th>
					<th>开始时间</th>
					<th>结束时间</th>
					<th>职能主管是否同意</th>
					<th>项目主管是否同意</th>
				</tr>
				<tr ng-repeat='leave in leaves'>
					<td ng-bind='leave.name'></td>
					<td ng-bind='leave.category'></td>
					<td ng-bind='leave.start_time'></td>
					<td ng-bind='leave.end_time'></td>
					<td ng-bind='leave.func_leader_approved'></td>
					<td ng-bind='leave.pro_leader_approved'></td>
				</tr>
			</table>
		</div>
		<!------------------------------------------->
		<div ng-switch-when='need_approve'>
			<button name="test" type="button" value="val" ng-click='submit_approve()'>提交</button>
			<p>作为职能主管</p>
			<table class="table table-hover">
				<tr>
				
					<th>员工</th>
					<th>类型</th>
					<th>开始时间</th>
					<th>结束时间</th>
					<th>职能主管是否同意</th>
					<th>项目主管是否同意</th>
				</tr>
				<tr ng-repeat='leave in func_leader_msg'>
				
					<td ng-bind='leave.name'></td>
					<td ng-bind='leave.category'></td>
					<td ng-bind='leave.start_time'></td>
					<td ng-bind='leave.end_time'></td>
					<td></span><input type="checkbox" name="check" ng-model='leave.func_leader_approved' /></td>
					<td ng-bind='{true:"YES",false:"NO"}[leave.pro_leader_approved]'></td>
				</tr>
			</table>

			<p>作为项目主管</p>
			<table class="table table-hover">
				<tr>
					<th>员工</th>
					<th>类型</th>
					<th>开始时间</th>
					<th>结束时间</th>
					<th>职能主管是否同意</th>
					<th>项目主管是否同意</th>
				</tr>
				<tr ng-repeat='leave in pro_leader_msg'>
					<td ng-bind='leave.name'></td>
					<td ng-bind='leave.category'></td>
					<td ng-bind='leave.start_time'></td>
					<td ng-bind='leave.end_time'></td>
					<td ><span ng-bind='{true:"YES",false:"NO"}[leave.func_leader_approved]'></span></td>
					<td><input type="checkbox" name="check" ng-model='leave.pro_leader_approved' /></td>
				</tr>
			</table>
			
		</div>
		<!-------------------查询实时信息------------------------>
		<div ng-switch-when='realtime_info'>
				<table class="table table-hover">
				<tr>
					<th>姓名</th>
					<th>16年</th>
					<th>16年剩余</th>
					<th>15年</th>
					<th>15年剩余</th>
					<th>剩余调休</th>
				</tr>
				<tr>
					<td ng-bind='real_info.name'></td>
					
					<td ng-bind='real_info.thisyear'></td>
					<td ng-bind='real_info.thisleft'></td>
					<td ng-bind='real_info.lastyear'></td>
					<td ng-bind='real_info.lastleft'></td>
					<td ng-bind='real_info.left_swap_off'></td>
				</tr>
			</table>
		</div>

		<!-------------------导入考勤------------------------>

		<div ng-switch-when='attend_view'>
			<button name="test" type="button" value="val" ng-click='import_attend()'>导入测试考勤数据</button>
			<button name="sss" type="button" value="val" ng-click='report_attend()'>刷新9月份报告</button>
			<button name="test" type="button" value="val" ng-click='complet_staff()'>完善</button>
		</div>

		<!-------------------临时连接------------------------>

		<div ng-switch-when='links'>
			<a href="/attendance/applyleave">请假</a><br/>
			<a href="/attendance/leave_record">请假记录查询</a><br/>
			<a href="/attendance/leave_detail/2">请假条详情</a><br/>
			<a href="/attendance/leave_query">剩余假期查询</a><br/>
			<a href="/attendance/attendance_report">考勤报告</a><br/>
			<a href="/attendance/leave_approve/2">消息审批</a><br/>
			<a href="/attendance/approval_history">领导审批记录</a>
		</div>
		
	</div>

</div>
{% endblock %}